﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using AForge.Imaging.Filters;

namespace Imaging
{
    public partial class HSBColorFilterUC : UserControl, IFilterConfig
    {
        private HSLFiltering colorFilter = new AForge.Imaging.Filters.HSLFiltering();

        public HSBColorFilterUC()
        {
            InitializeComponent();
            this.colorFilter.Hue = new AForge.IntRange(0, 359);
            this.colorFilter.Saturation = new AForge.DoubleRange(0, 1);
            this.colorFilter.Luminance = new AForge.DoubleRange(0, 1);
        }

        private void tb_Scroll(object sender, EventArgs e)
        {
            this.colorFilter.Hue = new AForge.IntRange(tbRedLow.Value, tbRedHigh.Value);
            this.colorFilter.Saturation = new AForge.DoubleRange(
                Math.Min(tbGreenHigh.Value, tbGreenLow.Value) / 255.0,
                Math.Max(tbGreenHigh.Value, tbGreenLow.Value) / 255.0);
            this.colorFilter.Luminance = new AForge.DoubleRange(
                Math.Min(tbBlueHigh.Value, tbBlueLow.Value) / 255.0,
                Math.Max(tbBlueHigh.Value, tbBlueLow.Value) / 255.0);
        }

        #region IFilterConfig Members

        public IFilter Filter
        {
            get { 
                return this.colorFilter;
            }
        }

        public UserControl FilterGUI
        {
            get {
                return this;
            }
        }

        public string FilterName
        {
            get
            {
                return "HSL Color filter";
            }
        }

        #endregion

        public override string ToString()
        {
            return this.FilterName;
        }
    }
}
